package test;

import com.alibaba.fastjson.JSON;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 描述: TODO
 * 作者: yanruizhi
 * 时间: 2023/7/19 16:14
 */
@SpringBootTest(classes = MyTestClass.class)
public class MyTestClass {
    /**
     * 将两个字符数组合并成一个新的字符数组
     *
     * @return [z,  h,  a,  n,  g, s,  a,  n]
     */
    @Test
    private static void test11() {
        String[] arr = {"z, h, a, n, g", "s, a, n"};
        List<String> list = Arrays.asList(arr);
        List<String> collect = list.stream().flatMap(x -> {
            String[] array = x.split(",");
            Stream<String> stream = Arrays.stream(array);
            return stream;
        }).collect(Collectors.toList());
        System.out.println(collect);
    }

    //https://restapi.amap.com/v3/ip?ip=114.247.50.2&output=xml&key=<用户的key>

    //https://qifu-api.baidubce.com/ip/geo/v1/district?ip=117.64.148.17


    @Test
    public void getLocation() {

        RestTemplate restTemplate = new RestTemplate();
        //        Object forObject = restTemplate.getForObject("https://restapi.amap.com/v3/ip?&key=458cdb74329deb3082db38ff548eb5f0", Object.class);
        Object forObject = restTemplate.getForObject("https://qifu-api.baidubce.com/ip/geo/v1/district?", Object.class);
        String string = JSON.toJSONString(forObject);
        System.out.println(string);
    }




}
